using System.ComponentModel;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace AssetImporter
{
    public class MainWindow : GameWindow
    {
        readonly Action<double> LoopFunc;
        IInputHandle inputHandle;
        public Action<int, int> OnWindowReset { get; set; }
        public MainWindow(int width, int height, Action<double> loopFunc, IInputHandle inputHandle) : base(GameWindowSettings.Default, new NativeWindowSettings(){ Size = new Vector2i(width, height), APIVersion = new Version(3, 3) })
        {
            LoopFunc = loopFunc;
            this.inputHandle = inputHandle;
            OnWindowReset = (int _, int _)=>{};
        }

        protected override void OnLoad()
        {
            base.OnLoad();

            Title = "Asset Importer";
        }

        protected override void OnResize(ResizeEventArgs e)
        {
            base.OnResize(e);
            OnWindowReset(e.Width, e.Height);
        }

        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);
            LoopFunc(e.Time);
        }

        protected override void OnTextInput(TextInputEventArgs e)
        {
            base.OnTextInput(e);
            inputHandle.OnTextInput(e.Unicode);
        }

        protected override void OnMouseWheel(MouseWheelEventArgs e)
        {
            base.OnMouseWheel(e);
            inputHandle.OnMouseWheel(e.OffsetX, e.OffsetY);
        }
        
    }
}
